import {
  AudioSettings,
  InputSource,
  NetworkInterfacesData,
  OBSConfig,
} from '@/types';
import { request } from 'umi';

/**
 * 获取所有音频输入源
 */
export const getAudioInputSources = (server: string) => {
  return request<InputSource[]>(`${server}/os/getAudioInputSources`);
};

/**
 * 获取音频输出源
 */
export const getAudioOutputSources = (server: string) => {
  return request<InputSource[]>(`${server}/os/getAudioOutputSources`);
};

/**
 * 获取音频配置
 */
export const getAudioSettings = (server: string) => {
  return request<{
    send?: InputSource;
    receive?: InputSource;
  }>(`${server}/os/getAudioSettings`);
};

/**
 * 设置音频配置
 * @param audioSettings
 */
export const setAudioSettings = (
  server: string,
  audioSettings: AudioSettings,
): Promise<AudioSettings> => {
  return request(`${server}/os/setAudioSettings`, {
    method: 'post',
    data: audioSettings,
  });
};

/**
 * 获取所有网卡
 */
export const networkInterfaces = (
  server: string,
): Promise<NetworkInterfacesData[]> => {
  return request<NetworkInterfacesData[]>(`${server}/os/networkInterfaces`);
};

/**
 * 设置网卡
 * @param server
 * @param networkInterfacesData
 */
export const setNetworkInterface = (
  server: string,
  networkInterfacesData: NetworkInterfacesData,
) => {
  return request(`${server}/os/setNetworkInterface`, {
    method: 'post',
    data: networkInterfacesData,
  });
};

/**
 * 获取推流编码器
 */
export const getStreamEncoders = (server: string) => {
  return request<string[]>(`${server}/os/streamEncoders`);
};

/**
 * 获取录制编码器
 */
export const getRecEncoders = (server: string) => {
  return request<string[]>(`${server}/os/recEncoders`);
};

/**
 * 获取obs配置
 */
export const getOBSConfig = (server: string): any => {
  return request<OBSConfig>(`${server}/os/getOBSConfig`);
};

/**
 * 设置obs配置
 * @param server
 * @param obsConfig
 */
export const setOBSConfig = (server: string, obsConfig: OBSConfig) => {
  return request(`${server}/os/setOBSConfig`, {
    method: 'post',
    data: obsConfig,
  });
};
/**
 * 设置obs录制路径
 * @param server
 * @param recordPath
 */
export const setRecordPath = (server: string, recordPath: string) => {
  return request(`${server}/os/setRecordPath`, {
    params: { recordPath },
  });
};
/**
 * 上传录制视频
 * @param server
 * @param recordPath
 */
export const uploadVideo = (server: string, fileData: any) => {
  return request<any>(`${server}/api/patient/addPatient`, {
    method: 'post',
    getResponse: true,
    data: fileData,
  });
};
